package ${package.Controller};

import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
import java.util.List;

/**
* ${table.comment!}前端控制器
* @author 一蓑烟雨
* @date ${date}
* @version 1.0.0
*/
@Api(tags = "${table.comment!}控制器(${table.controllerName})")
@ApiSort(1)
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>
    private final ${table.serviceName} ${table.serviceName?substring(1)?uncap_first};
    @Autowired
    public ${table.controllerName}(${table.serviceName} ${table.serviceName?substring(1)?uncap_first}){
        this.${table.serviceName?substring(1)?uncap_first} = ${table.serviceName?substring(1)?uncap_first};
    }

    @ApiOperation(value = "根据条件分页查询${table.comment}信息")
    @ApiOperationSupport(order = 1)
    @GetMapping("/list")
    public List<${entity}> get${entity}List(@RequestParam(defaultValue = "1") Integer pageNum,
                                            @RequestParam(defaultValue = "20") Integer pageSize,
                                            ${entity} ${entity?uncap_first}, LocalDate[] dates){
        return ${table.serviceName?substring(1)?uncap_first}.get${entity}ListByPage(pageNum,pageSize,${entity?uncap_first},dates);
    }

    @ApiOperation(value = "添加${table.comment}信息")
    @ApiOperationSupport(order = 2)
    @PostMapping("/add")
    public ResultObj ins${entity}(@RequestBody ${entity} ${entity?uncap_first}){
        if(${table.serviceName?substring(1)?uncap_first}.ins${entity}(${entity?uncap_first})){
            return  ResultObj.success(ResultConst.INSERT_SUCCESS);
        }
        return ResultObj.error(ResultConst.INSERT_FAILED);
    }

    @ApiOperation(value = "更新${table.comment}信息")
    @ApiOperationSupport(order = 3)
    @PutMapping("/edit")
    public ResultObj upd${entity}(@RequestBody ${entity} ${entity?uncap_first}){
        if(${table.serviceName?substring(1)?uncap_first}.updateById(${entity?uncap_first})){
        return  ResultObj.success(ResultConst.UPDATE_SUCCESS);
        }
        return ResultObj.error(ResultConst.UPDATE_FAILED);
    }

    @ApiOperation(value = "删除${table.comment}信息(单个)")
    @ApiOperationSupport(order = 4)
    @DeleteMapping("/remove/{id}")
    public  ResultObj del${entity}ById(@ApiParam(name = "id", value = "主键id", required = true)
                                       @PathVariable Integer id){
        if(${table.serviceName?substring(1)?uncap_first}.removeById(id)){
            return  ResultObj.success(ResultConst.DELETE_SUCCESS);
        }
        return ResultObj.error(ResultConst.DELETE_FAILED);
    }

    @ApiOperation(value = "删除${table.comment}信息(批量)")
    @ApiOperationSupport(order = 5)
    @DeleteMapping("/removes")
    public  ResultObj del${entity}ByIds(Integer[] ids){
        if(${table.serviceName?substring(1)?uncap_first}.removeByIds(Arrays.asList(ids))){
            return  ResultObj.success(ResultConst.DELETES_SUCCESS);
        }
        return ResultObj.error(ResultConst.DELETES_FAILED);
    }
}
</#if>
